/*******************************************OVERVIEW*******************************************************
 
 Political Shocks and Asset Prices
 
 Replication do file
 
 Appendix E: Parameter Instability
 
 Version July 29 2021 
 
  
********************************************************************************************************************/

clear
set more off
#delimit ;

cd "/Users/ssaiegh/Files/Mac/UCSD/Carnahan/Shocks/Replication Files";

log using "Appendix E", replace text;

use "daily_sp_argentina_2020.dta";

gen case_id= _n;

tsset case_id;

gen event=(steward==1 | gov_change==1 | dem_change==1 | elec==1 | terror==1);

gen ret_nom=log(nominal/L.nominal);
gen ret_inf=log(inflation/L.inflation);
gen ret_dol=log(dollar/L.dollar);

/* Table E1: Structural Break Tests*/; 

/* Conditional Mean*/; 

qui: regress ret_nom L.ret_nom ret_sp;
predict res_nom, res;
gen var_nom=0.5*(res_nom-L.res_nom)^2;
estat sbsingle, breakvars(, constant) generate(swald) nodots swald;
list date if swald>46.901 & swald!=.;
drop swald;


qui: regress ret_inf L.ret_inf ret_sp_real;
predict res_inf, res;
gen var_inf=0.5*(res_inf-L.res_inf)^2;
estat sbsingle, breakvars(, constant) generate(swald) nodots swald;
list date if swald>1.48 & swald!=.;
drop swald;

qui: regress ret_dol L.ret_dol ret_sp_real;
predict res_dol, res;
gen var_dol=0.5*(res_dol-L.res_dol)^2;
estat sbsingle, breakvars(, constant) generate(swald) nodots swald;
list date if swald>2.183 & swald!=.;
drop swald;


/* Conditional Variance*/; 

qui: regress var_nom;
estat sbsingle, generate(swald) nodots swald;
list date if swald> 39.176 & swald!=.;
drop swald;

qui: regress var_inf;
estat sbsingle, generate(swald) nodots swald;
list date if swald> 47.205 & swald!=.;
drop swald;


qui: regress var_dol;
estat sbsingle, generate(swald) nodots swald;
list date if swald> 52.761 & swald!=.;
drop swald;

/* Unconditional Mean*/; 

regress ret_nom;
predict res_nom2, res;
gen var_nom2=0.5*(res_nom2-L.res_nom2)^2;
estat sbsingle, generate(swald) nodots swald;
list date if swald>  55.993 & swald!=.;
drop swald;

regress ret_inf;
predict res_inf2, res;
gen var_inf2=0.5*(res_inf2-L.res_inf2)^2;
estat sbsingle, generate(swald) nodots swald;
list date if swald>   2.262 & swald!=.;
drop swald;


regress ret_dol;
predict res_dol2, res;
gen var_dol2=0.5*(res_dol2-L.res_dol2)^2;
estat sbsingle, generate(swald) nodots swald;
list date if swald>  3.187 & swald!=.;
drop swald;

/* Unconditional Variance*/; 

qui: regress var_nom2;
estat sbsingle, generate(swald) nodots swald;
list date if swald>  34.481 & swald!=.;
drop swald;

qui: regress var_inf2;
estat sbsingle, generate(swald) nodots swald;
list date if swald>  44.849 & swald!=.;
drop swald;


qui: regress var_dol2;
estat sbsingle, generate(swald) nodots swald;
list date if swald>   47.099 & swald!=.;
drop swald;


/******************************************* IMPORTANT NOTE ******************************************************/;
 
/******* The Following Piece of Code uses the command estat sbcusum available in Stata 15 ****/;

/******* I will not run in previous versions of Stata 15 ****/;


/* Figure E1: Recursive CUSUM Process (Unconditional Mean)*/; 


regress ret_nom;
estat sbcusum;

regress ret_inf;
estat sbcusum;

regress ret_dol;
estat sbcusum;

/* Figure E2. Recursive CUSUM Process (Unconditional Volatility)*/;


/* Unconditional Mean*/; 

regress var_nom2;
estat sbcusum;

regress var_inf2;
estat sbcusum;

regress var_dol2;
estat sbcusum;


log c;
